<?php


namespace Reezy\AlipaySdk;


class OAuthClient
{
    /**
     * @return AlipaySdk
     */
    protected $sdk;
    protected $accessToken;
    protected $userId;

    /**
     * @return string
     */
    public function getAccessToken(): string
    {
        return $this->accessToken;
    }

    /**
     * @return string
     */
    public function getUserId(): string
    {
        return $this->userId;
    }


    public function __construct(AlipaySdk $sdk, string $accessToken, string $userId)
    {
        $this->sdk = $sdk;
        $this->accessToken = $accessToken;
        $this->userId = $userId;
    }


    /**
     * 支付宝会员授权信息查询接口
     * https://opendocs.alipay.com/apis/api_2/alipay.user.info.share
     *
     * @return mixed|null
     */
    public function getUserInfo()
    {
        $result = $this->sdk->execute('alipay.user.info.share', [
            'auth_token' => $this->accessToken,
        ]);
        return $result['code'] == 10000 ? $result : null;
    }

    /**
     * 支付宝钱包用户信息共享
     * https://opendocs.alipay.com/apis/api_33/alipay.user.userinfo.share
     *
     * @return mixed|null
     */
    public function getAuthInfo()
    {
        return $this->sdk->execute('alipay.user.userinfo.share', [
            'auth_token' => $this->accessToken,
        ]);
    }
}